﻿namespace = ek_steward_task

ek_steward_task.0001 = {
	title = ek_steward_task.0001.t
	desc = {
		# Same heritage?
		first_valid = {
			triggered_desc = {
				trigger = { scope:county.culture = { has_same_culture_heritage = root.culture } }
				desc = ek_steward_task.0001.desc.same_heritage
			}
			desc = ek_steward_task.0001.desc.other_heritage
		}
		# Nomadic?
		triggered_desc = {
			trigger = { scope:county.culture = { has_innovation = innovation_native_nomadic } }
			desc = ek_steward_task.0001.desc.nomadic
		}
		# Ending
		first_valid = {
			triggered_desc = {
				trigger = {
					has_variable = has_special_culture_conversion_option
					exists = scope:own_culture
					scope:own_culture = { has_innovation = innovation_denizens_lost_orsinium }
					scope:county = { target_is_de_jure_liege_or_above = title:k_orsinium }
				}
				desc = ek_steward_task.0001.desc.ending_orsinium_orcs
			}
			desc = ek_steward_task.0001.desc.ending
		}
	}
	
	theme = culture_change
	
	left_portrait = {
		character = root
		animation = personality_rational
	}
	
	
	immediate = {
		# Special options
		if = {
			limit = {
				culture = { has_innovation = innovation_denizens_lost_orsinium }
				scope:county = { target_is_de_jure_liege_or_above = title:k_orsinium }
			}
			set_variable = {
				name = has_special_culture_conversion_option
				value = yes
			}
		}
		
		# 4 generic options: Your own culture, 2 random ones from your culture group native, 1 nomadic, and one reload the event plox
		scope:county.culture = { save_scope_as = county_old_culture }
		scope:county.duchy = { save_scope_as = de_jure_duchy }
		ROOT.culture = {
			if = {
				limit = {
					culture_is_alive = yes
				}
				save_scope_as = own_culture
			}
		}
		scope:county = {
			random_in_list = {
				variable = native_culture_list
				limit = {
					NOT = { this = scope:county.culture }
					has_same_culture_heritage = root.culture
					is_target_in_global_variable_list = {
						name = culture_is_alive
						target = this
					}
					NOR = { this = scope:own_culture }
				}
				save_scope_as = native_culture_1
			}
			random_in_list = {
				variable = native_culture_list
				limit = {
					NOT = { this = scope:county.culture }
					has_same_culture_heritage = root.culture
					is_target_in_global_variable_list = {
						name = culture_is_alive
						target = this
					}
					NOR = { this = scope:own_culture this = scope:native_culture_1 }
				}
				save_scope_as = native_culture_2
			}
		}
		random_culture_global = {
			limit = {
				NOT = { this = scope:county.culture }
				has_same_culture_heritage = root.culture
				is_target_in_global_variable_list = {
					name = culture_is_alive
					target = this
				}
				has_innovation = innovation_native_nomadic
			}
			save_scope_as = nomadic_culture
		}
		
		### Fallback: If we don't have any of these, take some random cultures within your culture group (should be very rare)
		if = {
			limit = {
				NOR = {
					exists = scope:own_culture
					exists = scope:native_culture_1
					exists = scope:native_culture_2
					exists = scope:nomadic_culture
				}
			}
			random_culture_global = {
				limit = {
					NOT = { this = scope:county.culture }
					has_same_culture_heritage = root.culture
					is_target_in_global_variable_list = {
						name = culture_is_alive
						target = this
					}
				}
				save_scope_as = fallback_culture_1
			}
		}
		if = {
			limit = {
				NOR = {
					exists = scope:own_culture
					exists = scope:native_culture_1
					exists = scope:native_culture_2
					exists = scope:nomadic_culture
				}
			}
			random_culture_global = {
				limit = {
					NOT = { this = scope:county.culture }
					has_same_culture_heritage = root.culture
					is_target_in_global_variable_list = {
						name = culture_is_alive
						target = this
					}
					NOR = { this = scope:fallback_culture_1 }
				}
				save_scope_as = fallback_culture_2
			}
		}
		if = {
			limit = {
				NOR = {
					exists = scope:own_culture
					exists = scope:native_culture_1
					exists = scope:native_culture_2
					exists = scope:nomadic_culture
				}
			}
			random_culture_global = {
				limit = {
					NOT = { this = scope:county.culture }
					has_same_culture_heritage = root.culture
					is_target_in_global_variable_list = {
						name = culture_is_alive
						target = this
					}
					NOR = { this = scope:fallback_culture_1 this = scope:fallback_culture_2 }
				}
				save_scope_as = fallback_culture_3
			}
		}
	}
	
	### Special: Orcs in Orsinium
	option = {
		trigger = {
			has_variable = has_special_culture_conversion_option
			exists = scope:own_culture
			scope:own_culture = { has_innovation = innovation_denizens_lost_orsinium }
			scope:county = { target_is_de_jure_liege_or_above = title:k_orsinium }
		}
		name = ek_steward_task.0001.orcs_orsinium
		
		custom_tooltip = ek_steward_task.0001.convert_orcs_orsinium_tooltip
		custom_tooltip = ek_steward_task.0001.convert_own_culture_tooltip
	}
	
	### Generic options
	option = {
		trigger = {
			# NOT = { has_variable = has_special_culture_conversion_option }
			exists = scope:own_culture
		}
		name = ek_steward_task.0001.own_culture
		
		custom_tooltip = ek_steward_task.0001.convert_own_culture_tooltip
		
		
		if = { # Nomadic?
			limit = { scope:own_culture = { has_innovation = innovation_native_nomadic } }
			custom_tooltip = ek_steward_task.0001.nomadic_culture_not_native_tooltip
		}
		else_if = { # If not native, then we tell it'll be very long
			limit = {
				scope:county = {
					NOT = {
						is_target_in_variable_list = {
							name = native_culture_list
							target = scope:own_culture
						}
					}
				}
			}
			custom_tooltip = ek_steward_task.0001.own_culture_not_native_tooltip
		}
		
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:own_culture
			}
		}
	}
	
	option = {
		trigger = { exists = scope:native_culture_1 }
		name = ek_steward_task.0001.native_culture_1
		
		custom_tooltip = ek_steward_task.0001.convert_native_culture_1_tooltip
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:native_culture_1
			}
		}
	}
	
	option = {
		trigger = { exists = scope:native_culture_2 }
		name = ek_steward_task.0001.native_culture_2
		
		custom_tooltip = ek_steward_task.0001.convert_native_culture_2_tooltip
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:native_culture_2
			}
		}
	}
	
	option = {
		trigger = {
			exists = scope:nomadic_culture
			NOT = { scope:nomadic_culture = scope:own_culture }
		}
		name = ek_steward_task.0001.nomadic_culture
		
		custom_tooltip = ek_steward_task.0001.convert_nomadic_culture_tooltip
		custom_tooltip = ek_steward_task.0001.nomadic_culture_not_native_tooltip
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:nomadic_culture
			}
		}
	}
	
	## Fallback option
	option = {
		trigger = { exists = scope:fallback_culture_1 }
		name = ek_steward_task.0001.fallback_culture_1
		
		custom_tooltip = ek_steward_task.0001.convert_native_fallback_culture_tooltip
		custom_tooltip = ek_steward_task.0001.not_native_tooltip
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:fallback_culture_1
			}
		}
	}
	
	option = {
		trigger = { exists = scope:fallback_culture_2 }
		name = ek_steward_task.0001.fallback_culture_2
		
		custom_tooltip = ek_steward_task.0001.convert_native_fallback_culture_tooltip
		custom_tooltip = ek_steward_task.0001.not_native_tooltip
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:fallback_culture_2
			}
		}
	}
	
	option = {
		trigger = { exists = scope:fallback_culture_3 }
		name = ek_steward_task.0001.fallback_culture_3
		
		custom_tooltip = ek_steward_task.0001.not_native_tooltip
		scope:county = {
			set_variable = {
				name = culture_to_convert
				value = scope:fallback_culture_3
			}
		}
	}
	
	option = {
		trigger = {
			OR = {
				exists = scope:own_culture
				exists = scope:native_culture_1
				exists = scope:native_culture_2
				exists = scope:nomadic_culture
				exists = scope:fallback_culture_1
				exists = scope:fallback_culture_2
				exists = scope:fallback_culture_3
			}
		}
		name = ek_steward_task.0001.refresh
		
		custom_tooltip = ek_steward_task.0001.refresh_cultures
		trigger_event = { id = ek_steward_task.0001 }
	}
	
	option = {
		trigger = {
			NOR = {
				exists = scope:own_culture
				exists = scope:native_culture_1
				exists = scope:native_culture_2
				exists = scope:nomadic_culture
				exists = scope:fallback_culture_1
				exists = scope:fallback_culture_2
				exists = scope:fallback_culture_3
			}
		}
		name = ek_steward_task.0001.no_culture
	}
}
